package com.wh.common.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.wh.common.pojo.TaskEmployee;
import com.wh.common.service.ITaskEmployeeService;
import com.wh.common.dao.TaskEmployeeMapper;
import com.wh.common.dto.TaskEmployeeDto;

import java.util.List;

/**
 * 业务实现类：
 */
@Service
public class TaskEmployeeServiceImpl implements ITaskEmployeeService {

    @Autowired
    private TaskEmployeeMapper taskEmployeeMapper;

    @Override
    public void add(TaskEmployee taskEmployee){
        taskEmployeeMapper.insert(taskEmployee);
    }

    @Override
    public void deleteById(Long id){
        taskEmployeeMapper.deleteById(id);
    }

    @Transactional
    @Override
    public void patchDel(List<Long> ids){
        taskEmployeeMapper.deleteBatchIds(ids);
    }

    @Override
    public void updateById(TaskEmployee taskEmployee){
        taskEmployeeMapper.updateById(taskEmployee);
    }

    @Override
    public TaskEmployee findOne(Long id){
        return taskEmployeeMapper.selectById(id);
    }

    @Override
    public List<TaskEmployee>findAll(){
        return taskEmployeeMapper.selectList(null);
    }

    @Override
    public IPage<TaskEmployee>findByPage(TaskEmployeeDto taskEmployeeDto){
        //1.创建查询条件
        QueryWrapper<TaskEmployee> qw = new QueryWrapper<>();
        //qw.like("xxx",taskEmployeeDto.getXxx());
        //qw.or();
        //qw.like("xxx",taskEmployeeDto.getXxx());
        //2.组件分页数据
        IPage<TaskEmployee> page = new Page<>(taskEmployeeDto.getCurrentPage(), taskEmployeeDto.getPageSize());
        page.setRecords(taskEmployeeMapper.findByPage(page,qw));
        page.setTotal(taskEmployeeMapper.selectCount(qw));
        //3.返回
        return page;
    }
}
